﻿function readAlbums(authorID, callback) {
	$.ajax({
		url: "http://picasaweb.google.com/data/feed/api/user/" + authorID,
		cache: false,
		data: {
			alt: "json",
			fields: "entry(gphoto:id,title)"
		},
		dataType: "jsonp",
		success: function(albums) {
			albums = $.map(albums.feed.entry, function(i) {
				return {
					title: i.title.$t,
					id: i.gphoto$id.$t
				};
			});
			callback(albums);
		}
	});
}

function readAlbumPhotos(maxSize, authorID, albumID, callback) {
	$.ajax({
		url: "http://picasaweb.google.com/data/feed/api/user/" + authorID + "/albumid/" + albumID,
		cache: false,
		data: {
			alt: "json",
			imgmax: Math.min(maxSize, 1600),
			thumbsize: "104u",
			fields: "entry(content(@src),gphoto:width,gphoto:height,title,media:group(media:thumbnail))"
		},
		dataType: "jsonp",
		success: function (photos) {
			photos = $.map(photos.feed.entry, function (i) {
				return {
					title: i.title.$t,
					src: i.content.src,
					height: 1 * i.gphoto$height.$t,
					width: 1 * i.gphoto$width.$t,
					thumbnail: {
						src: i.media$group.media$thumbnail[0].url,
						height: i.media$group.media$thumbnail[0].height,
						width: i.media$group.media$thumbnail[0].width
					}
				};
			});
			callback(photos);
		}
	});
}
